home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / FILER / TARSRC.SPK / c / timecon < prev   
Text File  |  1993-11-10  |  2KB  |  88 lines

  1.  
  2. #include <limits.h>
  3.  
  4. #include "timecon.h"
  5. #include "tar.h"
  6.  
  7.  
  8. static unsigned char TimeShift[5] = { 96, 106, 153, 110, 51 };
  9.  
  10.  
  11. void unix_to_fs_time(unsigned char *fstime, unsigned long unixtime) {
  12.   int Cnt;
  13.   signed long Carry,tmp;
  14.  
  15.   fstime[4] = 0;
  16.   fstime[3] = (unsigned char)(unixtime >> 24);
  17.   fstime[2] = (unsigned char)(unixtime >> 16) & 255;
  18.   fstime[1] = (unsigned char)(unixtime >>  8) & 255;
  19.   fstime[0] = (unsigned char)(unixtime & 255);
  20.   Carry = 0;
  21.   Cnt = 0;
  22.   while (Cnt <= 4) {
  23.     tmp = (long)fstime[Cnt] * 100L + Carry;
  24.     Carry = 0;
  25.     while (tmp >= 256) {
  26.       Carry++;
  27.       tmp -= 256;
  28.     }
  29.     fstime[Cnt] = (unsigned char)tmp;
  30.     Cnt++;
  31.   }
  32.   Carry = 0;
  33.   Cnt = 0;
  34.   while (Cnt <= 4) {
  35.     tmp = (long)fstime[Cnt] + (long)TimeShift[Cnt] + Carry;
  36.     Carry = 0;
  37.     if (tmp >= 256) {
  38.       Carry = 1;
  39.       tmp -= 256;
  40.     }
  41.     fstime[Cnt] = (unsigned char)tmp;
  42.     Cnt++;
  43.   }
  44. } /* unix_to_fs_time */
  45.  
  46.  
  47. unsigned long fs_to_unix_time(unsigned char *FStime) {
  48.   signed int Cnt;
  49.   signed long tmp,Carry,divident;
  50.   unsigned char fstime[5];
  51.  
  52.   Cnt = 0;
  53.   Carry = 0;
  54.   while (Cnt <= 4) {
  55.     tmp = (long)FStime[Cnt] - (long)TimeShift[Cnt] - Carry;
  56.     Carry = 0;
  57.     if (tmp < 0) {
  58.       tmp += 256;
  59.       Carry = 1;
  60.     }
  61.     fstime[Cnt] = (unsigned char)tmp;
  62.     Cnt++;
  63.   }
  64.   if (Carry > 0) {
  65.     fprintf(stderr,"tar: warning: UNIX time underflow\n");
  66.     return 0;
  67.   }
  68.   Cnt = 4;
  69.   Carry = 0;
  70.   while (Cnt >= 0) {
  71.     divident = (Carry * 256 + fstime[Cnt]); 
  72.     tmp =  divident / 100;
  73.     Carry = divident - tmp * 100;
  74.     fstime[Cnt] = (unsigned char)tmp;
  75.     Cnt--;
  76.   }
  77.   if (Carry * 256 / 100 >= 128)
  78.     fstime[0]++;
  79.   if (fstime[4] > 0) {
  80.     fprintf(stderr,"tar: warning: UNIX time overflow");
  81.     return ULONG_MAX;
  82.   } else
  83.     return (long)fstime[0] +
  84.            (long)fstime[1] * 256L +
  85.            (long)fstime[2] * 256L * 256L +
  86.            (long)fstime[3] * 256L * 256L * 256L;
  87. } /* fs_to_unix_time */
  88.